home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * fastobj -
- * support for spin format objects. This is obsoleted
- * by sgiobj files.
- *
- * Paul Haeberli - 1989
- */
- #include "stdio.h"
- #include "gl.h"
- #include "device.h"
- #include "spin.h"
- #include "resource.h"
-
- #define POLYGON 0
- #define LINES 1
-
- int lflag;
-
- #define PolyOrLine() if (lflag == LINES) { \
- bgnclosedline(); \
- } else { \
- bgnpolygon(); \
- }
-
- #define EndPolyOrLine() if (lflag == LINES) { \
- endclosedline(); \
- } else { \
- endpolygon(); \
- }
-
- fastobjlines(v)
- int v;
- {
- if(v)
- lflag = LINES;
- else
- lflag = POLYGON;
- }
-
- fastobj *readfastobj(name)
- char *name;
- {
- FILE *inf;
- fastobj *obj;
- int nlongs;
- int magic;
- char filename[512];
-
- inf = res_fopen(name,"r");
- if(!inf) {
- fprintf(stderr,"readfastobj: can't open input file %s\n",name);
- exit(1);
- }
- res_fread(&magic,sizeof(int),1,inf);
- if(magic != FASTMAGIC) {
- fprintf(stderr,"readfastobj: bad magic %d in object file\n",magic);
- fclose(inf);
- exit(1);
- }
- obj = (fastobj *)mymalloc(sizeof(fastobj));
- res_fread(&obj->npoints,sizeof(int),1,inf);
- res_fread(&obj->colors,sizeof(int),1,inf);
- nlongs = 6*obj->npoints;
- obj->data = (int *)mymalloc(nlongs*sizeof(int));
- res_fread(obj->data,nlongs*sizeof(int),1,inf);
- res_fclose(inf);
- return obj;
- }
-
- writefastobj(name,obj)
- char *name;
- fastobj *obj;
- {
- FILE *outf;
- int nlongs;
- int magic;
- char filename[512];
-
- outf = fopen(name,"w");
- if(!outf) {
- fprintf(stderr,"writefastobj: can't open input file %s\n",name);
- exit(1);
- }
- magic = FASTMAGIC;
- fwrite(&magic,sizeof(int),1,outf);
- fwrite(&obj->npoints,sizeof(int),1,outf);
- fwrite(&obj->colors,sizeof(int),1,outf);
- nlongs = 6*obj->npoints;
- fwrite(obj->data,nlongs*sizeof(int),1,outf);
- fclose(outf);
- }
-
- fastobj *clonefastobj(obj)
- fastobj *obj;
- {
- fastobj *cobj;
- int nlongs;
-
- cobj = (fastobj *)mymalloc(sizeof(fastobj));
- *cobj = *obj;
- nlongs = 6*obj->npoints;
- cobj->data = (int *)mymalloc(nlongs*sizeof(int));
- bcopy(obj->data,cobj->data,nlongs*sizeof(int));
- return cobj;
- }
-
- fastobj *newfastobj(npolys)
- int npolys;
- {
- fastobj *obj;
- int nlongs;
-
- obj = (fastobj *)mymalloc(sizeof(fastobj));
- obj->colors = 0;
- obj->npoints = 4*npolys;
- nlongs = 6*obj->npoints;
- obj->data = (int *)mymalloc(nlongs*sizeof(int));
- return obj;
- }
-
- drawfastobj(obj)
- fastobj *obj;
- {
- register long *p, *end;
- register int npolys;
-
- p = (long *)obj->data;
- end = (long *)(p + 6*obj->npoints);
- if(obj->colors) {
- npolys = obj->npoints/4;
- while(npolys--) {
- PolyOrLine();
- c3i(p);
- v3f((float*)p+3);
- p += 6;
- c3i(p);
- v3f((float*)p+3);
- p += 6;
- c3i(p);
- v3f((float*)p+3);
- p += 6;
- c3i(p);
- v3f((float*)p+3);
- p += 6;
- EndPolyOrLine();
- }
- } else {
- while ( p < end) {
- PolyOrLine();
- n3f((float*)p);
- v3f((float*)p+3);
- n3f((float*)p+6);
- v3f((float*)p+9);
- n3f((float*)p+12);
- v3f((float*)p+15);
- n3f((float*)p+18);
- v3f((float*)p+21);
- EndPolyOrLine();
- p+=24;
- }
- }
- }
-
- drawflatobj(obj)
- fastobj *obj;
- {
- register int *p,*end;
- register int npolys;
-
- p = obj->data;
- end = p + 6*obj->npoints;
- while ( p < end) {
- bgnpolygon();
- v3f((float*)p+3);
- v3f((float*)p+9);
- v3f((float*)p+15);
- endpolygon();
- bgnpolygon();
- v3f((float*)p+15);
- v3f((float*)p+21);
- v3f((float*)p+3);
- endpolygon();
- p+=24;
- }
- }
-